无法在Win系统上的Ubuntu虚拟机中安装Scrapy(Shell)

时间:2018-09-15 23:52:24

标签: python ubuntu scrapy vagrant scrapy-shell

我是VM的新手,但正在关注DKL撰写的《 Learning Scrapy》一书。似乎正在通过Vagrant和VirtualBox设置虚拟环境。我想我已经完成了所有工作-已安装ubuntu 12.04.5 LTS的Vagrant和VirtualBox。

然后我使用Cmder.exe(在我的项目文件夹e:... \ Project中)访问Vagrant

import React from "react";
import ReactDOM from "react-dom";

import "./styles.css";

const MAX = 3;

class Clickity extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      numbers: []
    }
  }

  generateRand = () => {
    // generate a random number 1 - MAX (3)
    let rand = Math.floor(Math.random() * MAX + 1);
    let { numbers } = this.state;

    // if length of array is equal to max return 0
    if (numbers.length === MAX) return 0;

    // check if generated number is in array
    if (numbers.includes(rand)) {
      console.log(`found a duplicate ${rand}`)
      // recursively run method
      this.generateRand();
    } else {
      // return the random number
      console.log(`returning ${rand}`)
      return rand;
    }
  }

  addNewNumber = () => {
    let id = this.generateRand();
    console.log(`retrieved ${id}`)
    let { numbers } = this.state;
    numbers.push(id);
    this.setState({ numbers });
  }

  render() {
    return (
      <div>
        <a onClick={() => this.addNewNumber()}>Generate unique number</a>
        <ul>{this.state.numbers.map((num) => <li>{num}</li>)}</ul>
      </div>
    )
  }
}

function App() {
  return (
    <Clickity />
  );
}

const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);

2 个答案:

答案 0 :(得分:0)

您可以尝试:

sudo apt-cache search scrapy

找出软件包名称。在新的Ubuntu系统上,程序包名称为python-scrapy,因此:

sudo apt-get install python-scrapy

答案 1 :(得分:0)

您始终可以使用pip安装Scrapy:

pip install scrapy